package com.yueke.gemini.modules.weblog.controller;
import java.io.IOException;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.yueke.gemini.modules.weblog.WebSockeService;
import com.yueke.gemini.utils.R;

/**
 * 
 * @author qxw
 * @data 2018年11月8日下午5:31:45
 */
@Controller
@RequestMapping("/weblog")
public class WebLogController {

   
   
	/**
	 * 页面请求
	 * @param cid
	 * @return
	 */
	@GetMapping("/socket/{cid}")
	public ModelAndView socket(@PathVariable String cid) {
		ModelAndView mav = new ModelAndView();
		mav.addObject("cid", cid);
		mav.setViewName("websocket");
		return mav;
	}

	/**
	 * 推送数据接口
	 * @param cid
	 * @param message
	 * @return
	 */
	@ResponseBody
	@RequestMapping("/socket/push/{cid}")
	public R pushToWeb(@PathVariable String cid, String message) {
		try {
			WebSockeService.sendInfo(message, cid);
		} catch (IOException e) {
			e.printStackTrace();
			return R.error();
		}
		return R.ok();
	}

}
